/*
Copyright 2010 Peter Krajnc, SCREENWORKER

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.screenworker.compactmvc.extensions.factoryservice.resourcetypes
{
	import com.screenworker.compactmvc.extensions.factoryservice.events.FactoryServiceEvent;
	import com.screenworker.compactmvc.extensions.interfaces.IResourceType;
	
	import flash.events.EventDispatcher;
	import flash.system.ApplicationDomain;

	public class ResourceRemote extends EventDispatcher implements IResourceType
	{
		private var _progress:Number = 0;
		private var _name:String;
		private var _isComplete:Boolean;
		
		public function ResourceRemote(name:String)
		{
			super();
			_name = name;
			_isComplete = false;
		}	
		
		public function reset():void
		{
			
		}	

		public function startLoading():void
        {
        	//not used here
        }
        
        public function stopLoading():void
        {     
        	//not used here
        }
        
		public function get progress():Number
        {
        	return _progress;
        }
        
        public function set progress(value:Number):void
		{
			//chech for infinity value. This only occurs in IE, safari, Opera (not firefox) by loading php manipulated xml files (totalLength is 0 and bytesloaded =>0)
			if(!isFinite(value))
				value = 1;
			_progress = value;
		}
        
        public function get resourceName():String
        {
        	return _name;
        }
        
        public function get isComplete():Boolean
        {
        	return _isComplete;
        }
        
        public function set isComplete(value:Boolean):void
        {
        	_isComplete = value;
        	_progress = 1;
        	if(_isComplete)
        		dispatchEvent(new FactoryServiceEvent(FactoryServiceEvent.COMPLETE, resourceName) );
        }
        
        public function get classReference():Class 
       	{
       		return null;
       	}
       	
       	 public function get applicationDomain():ApplicationDomain
       	{
       		return null;
       	}
	}
}
